package com.mh.view;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.EventQueue;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.ImageIcon;
import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

public class MainFrame extends JFrame {

	private JPanel contentPane;
	private JDesktopPane desktopPane = null;
	/**
	 * Create the frame.
	 */
	public MainFrame() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setResizable(false);
		setIconImage(Toolkit.getDefaultToolkit().getImage(MainFrame.class.getResource("/com/mh/images/logo.png")));
		setTitle("图书馆里系统主界面");
		setSize(1200, 820);
		setLocationRelativeTo(null);
		JMenuBar menuBar = new JMenuBar();
		setJMenuBar(menuBar);
		
		JMenu mnNewMenu = new JMenu("基本数据维护");
		mnNewMenu.setIcon(new ImageIcon(MainFrame.class.getResource("/com/mh/images/setting.png")));
		menuBar.add(mnNewMenu);
		
		JMenu mnNewMenu_2 = new JMenu("图书类别管理");
		mnNewMenu_2.setName("bookTypeManager");
		mnNewMenu.add(mnNewMenu_2);
		
		JMenuItem mntmNewMenuItem_2 = new JMenuItem("图书类别添加");
		mntmNewMenuItem_2.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				BookTypeAddFrame bookTypeAddFrame = new BookTypeAddFrame();
				bookTypeAddFrame.setVisible(true);
				desktopPane.add(bookTypeAddFrame);
			}
		});
		mntmNewMenuItem_2.setIcon(new ImageIcon(MainFrame.class.getResource("/com/mh/images/add.png")));
		mntmNewMenuItem_2.setName("bookTypeAdd");
		mnNewMenu_2.add(mntmNewMenuItem_2);
		
		JMenuItem mntmNewMenuItem_3 = new JMenuItem("图书类别维护");
		mntmNewMenuItem_3.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				BookTypeManageFrame bookTypeManageFrame = new BookTypeManageFrame();
				bookTypeManageFrame.setVisible(true);
				desktopPane.add(bookTypeManageFrame);
			}
		});
		mntmNewMenuItem_3.setIcon(new ImageIcon(MainFrame.class.getResource("/com/mh/images/edit.png")));
		mntmNewMenuItem_3.setName("bookTypeEdit");
		mnNewMenu_2.add(mntmNewMenuItem_3);
		
		JMenu mnNewMenu_3 = new JMenu("图书管理");
		mnNewMenu_3.setName("bookManager");
		mnNewMenu.add(mnNewMenu_3);
		
		JMenuItem bookAddFrame = new JMenuItem("图书添加");
		bookAddFrame.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				BookAddFrame bookAddFrame = new BookAddFrame();
				bookAddFrame.setVisible(true);
				desktopPane.add(bookAddFrame);
			}
		});
		bookAddFrame.setIcon(new ImageIcon(MainFrame.class.getResource("/com/mh/images/add.png")));
		mnNewMenu_3.add(bookAddFrame);
		
		JMenuItem mntmNewMenuItem_4 = new JMenuItem("图书管理");
		mntmNewMenuItem_4.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				BookManage bookManage = new BookManage();
				bookManage.setVisible(true);
				desktopPane.add(bookManage);
			}
		});
		mntmNewMenuItem_4.setIcon(new ImageIcon(MainFrame.class.getResource("/com/mh/images/edit.png")));
		mnNewMenu_3.add(mntmNewMenuItem_4);
		
		JMenuItem mntmNewMenuItem = new JMenuItem("安全退出");
		mntmNewMenuItem.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				int flag = JOptionPane.showConfirmDialog(null, "是否退出系统?","警告",JOptionPane.YES_NO_OPTION);
				if(0 == flag) dispose();
			}
		});
		mntmNewMenuItem.setName("exit");
		mnNewMenu.add(mntmNewMenuItem);
		
		JMenu mnNewMenu_1 = new JMenu("关于我们");
		mnNewMenu_1.setIcon(new ImageIcon(MainFrame.class.getResource("/com/mh/images/abort.png")));
		menuBar.add(mnNewMenu_1);
		
		JMenuItem mntmNewMenuItem_1 = new JMenuItem("关于图书管理系统");
		mntmNewMenuItem_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				abortActionPerformed(e);
			}
		});
		mntmNewMenuItem_1.setIcon(new ImageIcon(MainFrame.class.getResource("/com/mh/images/abort.png")));
		mntmNewMenuItem_1.setName("bookManagerDesc");
		mnNewMenu_1.add(mntmNewMenuItem_1);
		contentPane = new JPanel();
		contentPane.setName("mainFrame");
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(new BorderLayout(0, 0));
		
		desktopPane = new JDesktopPane();
		desktopPane.setBackground(Color.PINK);
		contentPane.add(desktopPane, BorderLayout.CENTER);
		//设置jframe最大化
//		this.setExtendedState(JFrame.MAXIMIZED_BOTH);
	}

	protected void abortActionPerformed(ActionEvent e) {
		BookInnerFrame table = new BookInnerFrame();
		table.setVisible(true);
		desktopPane.add(table);
	}
}
